{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# coding=utf-8\n",
    "from __future__ import print_function, absolute_import\n",
    "from gm.api import *\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import datetime\n",
    "import math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def init(context):\n",
    "    # 订阅bar\n",
    "    subscribe(symbols='SHSE.600000,SHSE.600004', frequency='30s', count=5, wait_group=True, wait_group_timeout='5s')\n",
    "    # 增加对象属性，如:设置一个股票资金占用百分比\n",
    "    context.percentage_stock = 0.8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'context' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[3], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m init(\u001b[43mcontext\u001b[49m)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'context' is not defined"
     ]
    }
   ],
   "source": [
    "init(context)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax. Perhaps you forgot a comma? (3035260682.py, line 11)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn[24], line 11\u001b[1;36m\u001b[0m\n\u001b[1;33m    Subcribe_data = context.data(symbol='SHSE.600000', frequency='tick', count=2)\u001b[0m\n\u001b[1;37m                    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax. Perhaps you forgot a comma?\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "run(strategy_id='859c3b0a-1765-11ec-acc4-d0509949eed8',\n",
    "        filename='main.py',\n",
    "        mode=MODE_BACKTEST,\n",
    "        token='bf739ec28ad507f391a3c3e99ed0365007da88f8',\n",
    "        backtest_start_time='2024-03-28 08:00:00',\n",
    "        backtest_end_time='2024-06-21 16:00:00',\n",
    "        backtest_adjust=ADJUST_PREV,\n",
    "        backtest_initial_cash=1000000,\n",
    "        backtest_commission_ratio=0.0007,\n",
    "        backtest_slippage_ratio=0.00123,\n",
    "        Subcribe_data = context.data(symbol='SHSE.600000', frequency='tick', count=2)\n",
    "        backtest_match_mode=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "Subcribe_data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'context' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[4], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m Subcribe_data \u001b[38;5;241m=\u001b[39m \u001b[43mcontext\u001b[49m\u001b[38;5;241m.\u001b[39mdata(symbol\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mSHSE.600000\u001b[39m\u001b[38;5;124m'\u001b[39m, frequency\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtick\u001b[39m\u001b[38;5;124m'\u001b[39m, count\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2\u001b[39m)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'context' is not defined"
     ]
    }
   ],
   "source": [
    "Subcribe_data = context.data(symbol='SHSE.600000', frequency='tick', count=2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "symbol = ['SHFE.rb2410']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'SHFE.rb2410'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "symbol[0]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
